UNAME := $(shell uname)

ifeq ($(UNAME), Linux)
	AS	= as --32
	LD	= ld
	#LDFLAGS = -m elf_i386 -x 
	LDFLAGS = -m elf_i386
	CC	= gcc
	CFLAGS  = -g -m32 -fno-builtin -fno-stack-protector -fomit-frame-pointer -fstrength-reduce #-Wall

	CPP	= cpp -nostdinc
	AR	= ar
	STRIP = strip
	OBJCOPY = objcopy
	# we should use -fno-stack-protector with gcc 4.3
	gcc_version=$(shell ls -l `which gcc` | tr '-' '\n' | tail -1)
endif



ifeq ($(UNAME), Darwin)

  #汇编语言编译程序。默认命令是 as
  AS = i386-elf-as

  # -g This is a common option used with software development tools signifying debugging information to be included in the output file.
  # --32 Generate 32-bit code. This option is only accepted on hosts with a native 64-bit system compiler.
  AFLAGS  = -g --32

  LD = i386-elf-ld

  # -m  This option specifies the emulation mode
  # elf_i386  The elf_i386 emulation mode tells the linker to create a 32-bit ELF-format output intended for an Intel i386 (or compatible) machine.
  LDFLAGS = -m elf_i386

  CC = i386-elf-gcc

  # -O0  This option sets the optimization level to 0. The compiler won't apply any optimizations to the code and will focus on reducing compilation time and making debugging work correctly.
  # -gdwarf-2 These options are related to debugging information. -gdwarf-2 tells gcc to output DWARF version 2 debugging information in the output executable,
  # -g3 includes additional debug information like macro definitions.
  # -m32 Generate 32-bit code. This option is only accepted on hosts with a native 64-bit system compiler.
  # -fno-builtin -fno-stack-protector -fomit-frame-pointer -fstrength-reduce: These are specific flags controlling how code is generated:
  #  -fno-builtin: Don't recognize built-in functions that do not begin with '_builtin' as prefix.
  #  -fno-stack-protector: Don't add security checks for stack overflows.
  #  -fomit-frame-pointer: Don't keep the frame pointer in a register for functions that don’t need one.
  #  -fstrength-reduce: Perform the optimizations of loop strength reduction.
  # -Wall:  enables all warning messages about constructions that some users consider questionable or are likely wrong.
  CFLAGS = -O0 -gdwarf-2 -g3 -m32 -fno-builtin -fno-stack-protector -fomit-frame-pointer -fstrength-reduce -Wall -nostdinc


  # -nostdinc: This is an option for the compiler driver program that tells it not to include standard system directories when searching for header files.
  # It's typically used when you're cross-compiling code or working in a specially-controlled build environment where you want absolute control over where included files come from.
  CPP     = i386-elf-cpp -nostdinc
  AR      = i386-elf-ar
  STRIP   = i386-elf-strip
  OBJCOPY = i386-elf-objcopy
endif


